﻿@{
    Layout = null;
    ViewData["Title"] = "Login";
}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>登入 - 益健橘红茶管理系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <environment include="Development">
        <link rel="stylesheet" href="~/layer/css/layui.css" media="all" />
        <link rel="stylesheet" href="~/layer/css/admin.css" media="all" />
        <link rel="stylesheet" href="~/layer/css/login.css" media="all">
    </environment>
    <environment exclude="Development">
        <link rel="stylesheet" href="~/layer/css/layui.css" asp-append-version="true" media="all" />
        <link rel="stylesheet" href="~/layer/css/admin.css" asp-append-version="true" media="all" />
        <link rel="stylesheet" href="~/layer/css/login.css" asp-append-version="true" media="all" />
    </environment>
</head>
<body>
    <div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display: none;">

        <div class="layadmin-user-login-main">
            <div class="layadmin-user-login-box layadmin-user-login-header">
                <h2>益健橘红茶管理系统</h2>
                <p></p>
            </div>
            <div class="layadmin-user-login-box layadmin-user-login-body layui-form">
                <div class="layui-form-item">
                    <label class="layadmin-user-login-icon layui-icon layui-icon-username" for="LAY-user-login-username"></label>
                    <input name="username" id="LAY-user-login-username" lay-verify="required" placeholder="会员编号/手机号" class="layui-input" />
                </div>
                <div class="layui-form-item">
                    <label class="layadmin-user-login-icon layui-icon layui-icon-password" for="LAY-user-login-password"></label>
                    <input type="password" name="password" id="LAY-user-login-password" lay-verify="required" placeholder="密码" class="layui-input">
                </div>
                <div class="layui-form-item">
                    <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="LAY-user-login-submit">登 入</button>
                </div>
            </div>
        </div>

        <div class="layui-trans layadmin-user-login-footer">

            <p>© 2018 <a href="javascript:;" target="_blank"></a></p>
        </div>

    </div>
    <script src="~/layer/layui.js"></script>
    <script>
        layui.config({
            base: '../../layer/' //静态资源所在路径
        }).extend({
            index: 'index' //主入口模块
        }).use(['index', 'user'], function () {
            var $ = layui.$
                , setter = layui.setter
                , admin = layui.admin
                , form = layui.form
                , router = layui.router()
                , search = router.search;

            var parentWin = window.parent;
            var parentDoc = parentWin.document;

            if (parentDoc.getElementsByClassName('layadmin-iframe').length > 0) {
                parentWin.location.href = '@Url.Action("login","account")';
            }

            form.render();

            //提交
            form.on('submit(LAY-user-login-submit)', function (obj) {
                //请求登入接口
                login(obj.field);
            });

            $(document).keyup(function (event) {
                if (event.keyCode == 13) {
                    var username = $('#LAY-user-login-username').val(),
                        password = $('#LAY-user-login-password').val(),
                        field = { username: username, password: password };

                    login(field);
                }
            });

            var login = function (field) {
                admin.req({
                    url: '@Url.Action("login", "api")' //实际使用请改成服务端真实接口
                    , data: field
                    , success: function (res) {
                        if (res.success && res.code == 0) {
                            layer.msg(res.message, {
                                offset: '15px'
                                , icon: 1
                                , time: 1000
                            }, function () {
                                location.href = '@Url.Action("index","home")'; //后台主页
                            });
                        } else {
                            layer.msg(res.message, { offset: '15px', icon: 2, time: 1000 });
                        }
                    }
                    , error: function (res) {
                        console.log(res);
                    }
                });
            }
        });

    </script>

</body>
</html>